package com.example.administrator.hqq.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;

import com.example.administrator.hqq.R;
import com.example.administrator.hqq.View.alertview.OnItemClickListener;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @name: HQQ
 * @describe:
 * @author: 康海涛 QQ2541849981
 * @time: 2018/12/5 11:48
 * @remark:
 */
public class ReportListAdapter extends BaseAdapter {
    List<String> list;
    Context context;
    private int position=-1;
    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public ReportListAdapter(List<String> list, Context context) {
        this.list = list;
        this.context = context;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
    @SuppressLint("ViewHolder")
    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.report_popup_list_item, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        viewHolder.reportRadio.setChecked(false);
        viewHolder.reportRadio.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener!=null)
                {
                    onItemClickListener.onItemClick(null,i);
                }
            }
        });
        viewHolder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener!=null)
                {
                    onItemClickListener.onItemClick(null,i);
                }
            }
        });
        viewHolder.reportText.setText(list.get(i));
        if (position==i)
        {
            viewHolder.reportRadio.setChecked(true);
        }
        return inflate;
    }

    static class ViewHolder {
        @BindView(R.id.report_text)
        TextView reportText;
        @BindView(R.id.report_radio)
        RadioButton reportRadio;
        View view;
        ViewHolder(View view) {
            this.view=view;
            ButterKnife.bind(this, view);
        }
    }
}
